package com.example.administrator.yuejian2.model;

import com.example.administrator.yuejian2.RetrofitListener.RetrofitListener;
import com.example.administrator.yuejian2.bean.ActivityBean;
import com.example.administrator.yuejian2.service.ActivityService;
import com.example.administrator.yuejian2.service.RetrofitService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static com.example.administrator.yuejian2.other.Url.BASEURL;
import static com.example.administrator.yuejian2.other.Url.URL;


public class ActivityModel {
    private Retrofit retrofit;
    private ActivityService activityService;
    public ActivityModel()
    {
        retrofit=new Retrofit.Builder()
                .baseUrl(BASEURL+URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        activityService=retrofit.create(ActivityService.class);
    }
    public void activityList(final RetrofitListener listener)
    {
        Call<List<ActivityBean>> call=activityService.activitylist();
        call.enqueue(new Callback<List<ActivityBean>>() {
            @Override
            public void onResponse(Call<List<ActivityBean>> call, Response<List<ActivityBean>> response) {
                listener.onSuccess(response.body(),1);
            }

            @Override
            public void onFailure(Call<List<ActivityBean>> call, Throwable t) {
                listener.onFail();
            }
        });
    }

}
